home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
029a
/
greq.zip
/
GREQ.DOC
< prev
Wrap
Text File
|
1991-12-31
|
14KB
|
507 lines
page 65,132
;GREQ.COM A very compact 'Stand Alone' file search routine
; with looping, case insensitivity.
;May also be used as utility search routine in other software
;
;12/31/91 Ted Dowling, WJ2T
;
;*********************************************
GREQ segment ;define code segment
ASSUME CS:GREQ
;---------------------------------------------
MAIN PROC FAR ;main part of program
nambuf1 equ 80h ;address of read file
wkb_siz equ 80 ;half size of wkb
org 100h
start: ;starting execution address
;set up stack for return
push ds ;save old data segment
sub ax,ax ;put zero in AX
push ax ;save it on stack
;---------------------------------------------
;---------------------------------------------
mov bx,offset nambuf1 ;filename location
call get_file ; test and prepare for handle assign
mov dx,offset nambuf1+2 ;now
mov bx,offset handle1 ; open the file
call open_file ;and store the handle
call cls ;clear screen
nxt_req:mov dx,offset greq_req ;send request message
call print_str ;local screen display
mov dx,offset key_buf ;search arg store
mov di,dx
call key ;buffered kbd input
inc dx ;DX=actual count
mov al,[di+1] ;check count
cmp al,0 ;no input?
jz greqend ;no, done
call find_req ; search and display
jmp nxt_req
greqend:
mov bx,offset handle1 ;pointer in BX
call close_file
ret
MAIN ENDP ;end main code
;*********************************************
;---------------------------------------------
PUBLIC FIND_REQ
;Sets file pointer to beginning of file then
;searches for argument string while placing bytes
;read in circular buffer. When string is found,
;continues to load buffer until occurrence of next
;CR
FIND_REQ PROC NEAR
call point_z ;zero the file pointer
mov al,1 ;now set
mov di,offset status ;status byte
mov [di],al ;reset all status
wkld0: mov dx,offset wkb0 ;circular buffer area #1
mov ah,1 ;set status
mov di,offset status
xor [di],ah
call read_file ;load wkb0
cmp ax,0 ;is EOF
jnz go1 ; no, continue
jmp dun_find
wkld1: mov dx,offset wkb1 ;circular buffer area #2
mov ah,1 ;set status
mov di,offset status
xor [di],ah
call read_file ;load wkb1
cmp ax,0 ;is EOF
jnz go1 ; no, continue
jmp dun_find
go1: mov di,offset status ;check for
mov al,[di] ; incomplete read
mov di,dx ;get wkb pointer start
test al,2 ;is bit 2 set?
jz nomch1 ; no
mov di,offset status ;reset
xor byte ptr [di],2 ;the incomplete
mov di,dx ;wkb pointer start
jmp fwd_pt1 ; yes, continue printing
nomch1: test al,4 ; incomplete test
jz nomch2 ; no
mov di,offset status ;reset
xor byte ptr [di],4 ;the incomplete
mov di,dx ;wkb pointer start
dec di ;adj for inc
jmp mach3 ; yes, continue testing
nomch2: test al,8 ;incomplete CR search fwd
jz nomch3 ;no
mov di,offset status ;reset
xor byte ptr [di],8 ;the incomplete CR
mov di,dx ;wkb pointer start
mov al,0dh ;reset al
jmp test_cr
nomch3: mov di,dx ;pointer start
dec di ; start down 1
mach2: mov si,offset key_buf+2 ;past counts
mach3: mov al,[si] ;get byte
inc di ;bump pointer
cmp al,0dh ;is end of argument?
jz test_cr ;yup, got one
mov ah,al ;set other case
cmp ah,5ah ;upper case 'Z'
jle case1 ;yes, or non alpha
cmp ah,61h ;lower case 'a'
jl case ; go, non-alpha
cmp ah,7ah ;lower case 'z'
jg case ; go, non-alpha
sub ah,20h ;change to upper case
jmp case ; and go
case1: cmp ah,41h ;upper case 'A'
jl case ; go, non-alpha
add ah,20h ;change to lower case
case: cmp al,[di] ; is byte a match?
jz mach1 ; yes
cmp ah,[di] ;check other case
jz mach1 ; yes
mov ah,1ah ;EOF byte
cmp ah,[di] ;check EOF
jnz mach5
jmp dun_find ;search req finished
mach5: loop mach2 ; no check next
;if loop falls through at this point we have run out
;of data with no match and must switch and load other wkb
jmp reload
;SI has pointed to CR at the end of argument meaning that
;total arg has been processed. We must now ensure that there
;is a CR following
test_cr:
cmp al,[di] ;is CR?
jz bakup ;yup, go to it
inc di ; no, bump
loop test_cr
mov bx,offset status ;need reload
mov ah,8 ;creload bit
or [bx],ah ;in status
reload: mov bx,offset status
mov ah,[bx]
test ah,1 ;active wkb=1?
jz rlod1 ; for long jump
jmp wkld0 ;yes, now load wkb0
rlod1: jmp wkld1 ; yes, load wkb1
mach1: inc si ;check next too!
loop mach3
;if loop falls through at this point we have run out
;of matching data in wkb and must load and continue test
;in other wkb
mov bx,offset status ;status bit
mov al,4 ;#4 is incomplete test
or [bx],al ; test indicator
jmp reload
bakup:
;we have a complete match and have located forward CR
; and will now need to back up the DI pointer and find
; the last occurrence of a CR
push cx ;save count and
push di ;pointer at last byte
bakup1: dec di ;de_bump
mov al,[di] ;and check
cmp al,0ffh ;out of buffer wkb0?
jnz bakup2 ;no, continue read
mov di,offset wkbe-1 ;position DI to end wkb2
mov al,[di] ; and check first byte
bakup2: cmp al,0dh ;is CR?
jnz bakup1 ;no, continue back
inc di ; yes, now pass
mov al,[di] ; CR and check
cmp al,0ffh ;buffer end?
jnz bakup3 ; no, continue
mov di,offset wkb0 ;yes, loop to other wkb
mov al,[di] ; and check first byte
bakup3: cmp al,0ah ; for linefeed
jnz fwd_pt1 ;no, begin printing
fwd_pt: inc di
fwd_pt1:mov dl,[di] ;put chr in dl
cmp dl,0ffh ;is end of buffer?
jz fwd_pt2 ; yes, need more data
mov ah,2 ;display output function
int 21h ;call DOS
cmp dl,0dh ;is end line?
jnz fwd_pt ; no, get next char
mov dl,0ah ; add LF to CR
mov ah,2 ;display output function
int 21h ;call DOS
pop di ;restore end
pop cx ; of print
jmp mach5 ;end of this print
fwd_pt2:
;at this point we have run to the end of the buffer and
;have previously reloaded other buffer while searching
;for forward CR. Must now set DI to currently loaded
;buffer and cx to full wkb_siz
mov bx,offset status
mov al,1 ;check for buffer 1 active
test [bx],al ; if true then NZ
jnz buffer1 ;wkb1 was last loaded
mov di,offset wkb0 ;wkb0 was last loaded
jmp fwd_pt1
buffer1:mov di,offset wkb1
jmp fwd_pt1 ;and resume
dun_find: ret
FIND_REQ ENDP
;*********************************************
;---------------------------------------------
BUFFERS PROC NEAR
handle1:dw ?
db 0ffh ;end stop wkb0
status: db 0 ; bit1=wkb#,bit2=incomplete read
; bit3=incomplete test
; bit4=incomplete CR search
; bit5=match in progress
db 0ffh ;wkb delimiter at start
wkb0 db wkb_siz dup(0)
wkb1 db wkb_siz dup(0)
wkbe db 0ffh ;wkb delimiter at end
key_buf db 80,0,10 dup('key_bufr')
greq_req:db 0dh,0ah,0ah,'Enter Search Argument For Data Desired'
db 0dh,0ah,'Or press [ENTER] to terminate routine'
db 0dh,0ah,'> ','$'
BUFFERS ENDP
;*********************************************
;---------------------------------------------
PUBLIC READ_FILE
;reads the datafile. Enter with DX=buffer ptr
READ_FILE PROC NEAR
mov cx,wkb_siz ;read file size
mov bx,offset handle1 ;pointer in BX
mov bx,[bx] ;handle in BX
mov ah,3fh ;read file function
int 21h ;call DOS
jnc go2 ;error return?
jmp error ;yes, terminate pgm
go2: cmp ax,0 ;EOF?
jz endfile
ret
endfile:pop dx ;pseudo SP correct
ret
READ_FILE ENDP
;*********************************************
;---------------------------------------------
PUBLIC KEY
;get buffer size DS:DX, get keyboard to CR, leave
; string length DS:DX+1
KEY PROC NEAR
mov ah,0ah ;buffered keyboard
int 21h ;call DOS
ret
KEY ENDP
;*********************************************
;---------------------------------------------
PUBLIC GET_FILE
;gets file name of file to be read from entry
; and sets it up for handle assignment
; enter with BX pointing to fcb filename
GET_FILE PROC NEAR
mov al,[bx] ; check to see if
cmp al,0 ; filename installed
jnz newfile ;yes, continue
mov dx,offset nofile ;no file message
mov ah,9h ;print message funct
int 21h ;call DOS
jmp exit ;and exit
;ADJUST PATHNAME OF FILE TO BE OPENED
newfile:
mov bx,offset nambuf1 ;get # bytes read
mov bl,[bx]
mov bh,0 ; into BX
mov [byte ptr nambuf1+bx+1],0 ;zero into byte
done: ret
GET_FILE ENDP
;*********************************************
;---------------------------------------------
PUBLIC PRINT_STR
;Enter with DX pointing to string offset
;String ends with '$'
PRINT_STR PROC NEAR
mov ah,09h ;print string function
int 21h ;call DOS
ret
PRINT_STR ENDP
;*********************************************
;---------------------------------------------
PUBLIC ERROR
ERROR PROC NEAR
;error message generator using binihex converter
mov dx,offset emess ;error message
mov ah,9 ;print message function
int 21h ;call DOS
call binihex ;print error number
jmp exit
ERROR ENDP
;*********************************************
;---------------------------------------------
PUBLIC EXIT
EXIT PROC NEAR
pop dx ;Pseudo SP correction
jmp greqend
EXIT ENDP
;*********************************************
;---------------------------------------------
PUBLIC BINIHEX
BINIHEX PROC NEAR
mov ch,4
rotate: mov cl,4 ;set count to 4 bits
rol bx,cl ;left digit to right
mov al,bl ;move to al
and al,0fh ;mask off left digit
add al,30h ;convert to ascii
cmp al,3ah ;is it >9?
jl printit ;jump if digit =0-9
add al,7h ;digit=a to f
printit:
mov dl,al ;put ascii chr in dl
mov ah,2 ;display output function
int 21h ;call DOS
dec ch ;done 4 digits?
jnz rotate ;not yet
ret
BINIHEX ENDP
;*********************************************
;---------------------------------------------
PUBLIC OPEN_FILE
OPEN_FILE PROC NEAR
;opens file and stores handle
;enter with DX=address of filename; BX=handle storage buffer
mov al,0 ;file open for reading
mov ah,3dh ;open file function
int 21h ;call DOS
mov [bx],ax ; and store it
jc error ;error return?
ret
OPEN_FILE ENDP
;*********************************************
;---------------------------------------------
PUBLIC POINT_Z
;positions pointer to the beginning of the
;file specified by handle in BX
POINT_Z PROC NEAR
push cx ;save registers
push dx ;used
push bx
mov bx,offset handle1
xor cx,cx ;zero file
mov dx,cx ;vectors
call point_x ; and set pointer
pop bx
pop dx ; restore
pop cx ;registers used
ret
POINT_Z ENDP
;*********************************************
;---------------------------------------------
PUBLIC POINT_X
;positions pointer to point specified by CX:DX
;enter with BX=handle pointer
POINT_X PROC NEAR
mov bx,[bx] ;handle in BX
mov al,0 ;absoloute address
mov ah,42h ; for added new data
int 21h ;and call DOS again
ret
POINT_X ENDP
;*********************************************
;---------------------------------------------
PUBLIC CLOSE_FILE
CLOSE_FILE PROC NEAR
;closes file handle
;enter with BX=handle storage buffer
mov bx,[bx] ;put handle in BX
mov ah,3eh ;close file function
int 21h ;call DOS
jc error ;error return?
ret
CLOSE_FILE ENDP
;*********************************************
;---------------------------------------------
PUBLIC PRINT_MEM
;reads and screen prints buffer contents
;enter with BX=memory start; CX=read length
PRINT_MEM PROC NEAR
;DISPLAY BUFFER CONTENTS
mov dl,[bx] ;get byte in AL
inc bx ;and bump pointer
cmp dl,1ah ;is it EOF
jz endpr ;yes, stop printing
mov ah,02h ;char output routine
int 21h ;call DOS
cmp dl,0dh ;is CR
jnz print_mem; no get next byte
endpr: ret
PRINT_MEM ENDP
;*********************************************
;---------------------------------------------
PUBLIC CLS
;Clears the local screen
CLS PROC NEAR
mov bh,6
mov ah,0
mov al,3
int 10h
sub cx,cx
mov dh,18h ;80th row
mov dl,4fh ;24th column
xor al,al ;zero in AL
mov bh,07h ;color attribute
mov ah,06 ;scroll up function
int 10h ;BIOS call
ret
CLS ENDP
;*********************************************
;---------------------------------------------
nofile db 13,10,10,'GREQ.COM',13,10,10
db 'Ted Dowling, WJ2T, 12/31/91',13,10,10
db 13,10,'For use locating strings in a ASCII'
db 13,10,'file and displaying all occurrences'
db 13,10,13,10,'Line length of file must not exceed'
db 13,10,'screen width between carriage returns'
db 13,10,'use=GREQ [INFILE.EXT]'
db 13,10,10,' $'
emess db 'Error $'
;*********************************************
GREQ ENDS
end start ;end assembly